//
//  KAEmptyView.swift
//  kano
//
//  Created by Frank on 2024/9/30.
//

import UIKit
import ActiveLabel

class KAEmptyView: UIView {
    
    var handler: (()->())?
    
    
    lazy var tipTitle: ActiveLabel = {
        tipTitle = ActiveLabel()
        tipTitle.numberOfLines = 0
        tipTitle.text = "No loan record"
        tipTitle.textAlignment = .center
        //tipTitle.lineSpacing = kscale(8)
        tipTitle.font = UIFont.systemFont(ofSize: kscale(11), weight: .medium)
        tipTitle.textColor = .black
        return tipTitle
    }()
    
    lazy var selectBtn: UIButton = {
        let button = UIButton()
        button.setTitle("Apply now ", for: .normal)
        button.setTitleColor(.color8A8891, for: .normal)
        button.titleLabel?.font = kFontSize(kscale(12))
        button.setImage(UIImage(named: "mine_arrow"), for: .normal)
        button.setImage(UIImage(named: "mine_arrow"), for: .selected)
        button.addTarget(self, action: #selector(selectAllBtnClick(_:)), for: .touchUpInside)
        return button
    }()
    
    @objc func selectAllBtnClick(_ sender: UIButton) {
        sender.preventDoubleTap()
        if (handler != nil) {
            handler!()
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        ka_setUI()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func ka_setUI() {
        backgroundColor = .white
        addSubview(tipTitle)
        addSubview(selectBtn)
        
        tipTitle.snp.makeConstraints { make in
            make.left.right.equalTo(self)
            make.top.right.equalTo(kscale(22))
        }
        selectBtn.snp.makeConstraints { make in
            make.top.equalTo(tipTitle.snp.bottom).offset(kscale(12))
            make.centerX.equalTo(self)
        }
        
        selectBtn.imageEdgeInsets = UIEdgeInsets(top: 0, left: selectBtn.titleLabel!.intrinsicContentSize.width, bottom: 0, right: -selectBtn.titleLabel!.intrinsicContentSize.width)
        selectBtn.titleEdgeInsets = UIEdgeInsets(top: 0, left: -selectBtn.imageView!.intrinsicContentSize.width, bottom: 0, right: selectBtn.imageView!.intrinsicContentSize.width)
    }
}
